/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.myapp.util;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 *
 * @author elio
 */
public class ManipuladoraArquivo {
     private static final String DIRETORIO = "C://temp//";
     
     public static void criarArquivo(String nome, String filename, byte[] conteudo) throws FileNotFoundException, IOException{
      if (conteudo.length > 0){
            FileOutputStream outPut = new FileOutputStream(DIRETORIO + nome+ getExtensao(filename) );
            outPut.write(conteudo);
            }
     }
     
     private static String getExtensao(String fileName){
         int i = fileName.lastIndexOf('.');
          return fileName.substring(i);
     }
     
     public static void removerArquivo(String nome) {
        File baseFolder = new File(DIRETORIO);
        File[] files = baseFolder.listFiles();
        for (int i = 0; i < files.length; i++) {
            File file = files[i];
            String x[] = file.getName().split("\\.");
            if (x[0].equals(nome)) {
                file.delete();
            }
        }
    }
    
    
    
}
